{% extends 'base.html' %}

{% block  page-content %}

            <div class="row">
                <div class="col-lg-12">
                    <h1 class="page-header">用户修改</h1>
                </div>
                <!-- /.col-lg-12 -->
            </div>
            <!-- /.row -->

            {% for u in Userinfo %}
            <div class="row">
                <div class="col-lg-8">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            用户修改
                        </div>
                        <div  class="panel-body">
                    <form class="form-horizontal nice-validator n-yellow" method="post"  action="/account/edit/{{ edid }}" >

                        <div class="form-group"><label class="col-sm-2 control-label"> 用户名 <span class="red-fonts">*</span></label>
                            <div class="col-sm-6"><input type="text" class="form-control" name="username"  value="{{u.username}}" required="required" disabled></div>
                        </div>

                         <div class="form-group"><label class="col-sm-2 control-label"> 姓&nbsp;&nbsp;名 </label>
                            <div class="col-sm-6"><input type="text" class="form-control" name="nickname"  value="{{u.nickname}}" ></div>
                        </div>


                       <div class="form-group"><label class="col-sm-2 control-label"> 联系方式 </label>
                            <div class="col-sm-6"><input type="text" class="form-control" name="phone"  value="{{u.phone}}"  ></div>
                        </div>





                        <div class="form-group"><label class="col-sm-2 control-label"> 邮&nbsp;&nbsp;箱 <span class="red-fonts">*</span></label>
                            <div class="col-sm-6"><input type="text" class="form-control" name="email"  id="email"  value="{{u.email}}" required ></div>
                        </div>

                         <div class="form-group"><label class="col-sm-2 control-label"> 姓&nbsp;&nbsp;别 <span class="red-fonts">*</span></label>
                            <div class="col-sm-6 radio">
                                    <!-- 因在数据库里存储时用的字符串，所有获取值的时候要用""括起来-->
                                    {% if u.sex == "1" %}
                                            <label>
                                                    <input type="radio" name="sex" id="optionsRadios1" value="1" checked>
                                                        男
                                            </label>
                                             <label>
                                                    <input type="radio" name="sex" id="optionsRadios2" value="2" >
                                                        女
                                            </label>
                                    {%else%}
                                            <label>
                                                    <input type="radio" name="sex" id="optionsRadios1" value="1" >
                                                        男
                                            </label>
                                             <label>
                                                    <input type="radio" name="sex" id="optionsRadios2" value="2" checked>
                                                        女
                                            </label>
                                    {%endif%}

                                </div>
                        </div>
                        <div class="form-group"><label class="col-sm-2 control-label"> 激&nbsp;&nbsp;活 <span class="red-fonts">*</span></label>
                            <div class="col-sm-6 radio" >
                                 {% if u.is_active == 1 %}
                                            <label>
                                                    <input type="radio" name="isactive" id="optionsRadios1" value=1 checked>
                                                        是
                                            </label>
                                             <label>
                                                    <input type="radio" name="isactive" id="optionsRadios2" value=0 >
                                                        否
                                            </label>
                                {%else%}
                                            <label>
                                                    <input type="radio" name="isactive" id="optionsRadios1" value=1 >
                                                        是
                                            </label>
                                             <label>
                                                    <input type="radio" name="isactive" id="optionsRadios2" value=0 checked>
                                                        否
                                            </label>
                                {%endif%}
                                </div>
                        </div>

                        <div class="form-group"><label class="col-sm-2 control-label"> 部&nbsp;&nbsp;门 <span class="red-fonts">*</span></label>

                                <div class="col-sm-4">
                                    <select class="form-control" name="dept" required>
                                        {% for i in Deptlist %}
                                            {%if u.dept_id == i.id %}
                                                <option value="{{i.id}}" selected>{{i.name}}</option>
                                            {%else%}
                                                <option value="{{i.id}}">{{i.name}}</option>
                                            {%endif%}
                                        {%endfor%}
                                    </select>
                                </div>
                        </div>


                        <div class="form-group"><label class="col-sm-2 control-label"> 角&nbsp;&nbsp;色 <span class="red-fonts">*</span></label>
                                 <div class="col-sm-4">
                                    <select class="form-control" name="role" required>
                                        {% for k,v in list_roles.items%}
                                            {%if u.role == k%}
                                                 <option value={{k}} selected="selected">{{v}}</option>
                                            {%else%}
                                                 <option value={{k}}>{{v}}</option>
                                            {%endif%}
                                        {%endfor%}
                                    </select>
                                </div>
                        </div>


                         {% csrf_token %}
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-5">
                                <button type="reset" class="btn btn-white"> 重置 </button>
                                <button type="button" class="btn btn-primary" id="useradd"> 提交 </button>
                            </div>
                        </div>
                        <!--
                        <script>
                            var reg = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
                            if(!reg.test(email).val()){
                                alert("有限");

                            }
                        </script>-->


                    </form>
                    </div>
                    <!-- /.panel -->
                </div>

                    {% endfor %}
            </div>
                <div class="modal fade" id="myModal" tabindex="-1" role="dialog"  id="myModal" aria-labelledby="myModalLabel">
              <div class="modal-dialog" role="document">
                <div class="modal-content">
                  <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">系统提示</h4>
                  </div>
                  <div class="modal-body">
                         <p id="getdata">ddddddd</p>
                  </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <a class="btn btn-primary" href="/account/list/">确定</a>

                    </div>
                </div>
              </div>
            </div>




            <!-- /.row -->

                <script>
                       $(function(){

                            $("#useradd").click(function() {
                                var reg=/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;

                                if (!reg.test($("#email").val())) {
                                    　　$("#getdata").html("请输入正确的邮箱格式!!!");
                                        $('#myModal').modal('show');
                                        return false;
                                　}

                                $.post("",
                                         {username: $("input[name='username']").val(),
                                               nickname: $("input[name='nickname']").val(),
                                               phone: $("input[name='phone']").val(),

                                               email: $("input[name='email']").val(),
                                               sex: $("input[name='sex']:checked").val(),
                                               isactive: $("input[name='isactive']:checked").val(),
                                               dept: $("select[name='dept']").val(),
                                               role: $("select[name='role']").val(),
                                               csrfmiddlewaretoken: '{{ csrf_token }}'},
                                         function (data) {
                                            $("#getdata").html(data);
                                            $('#myModal').modal('show');
                                        });
                            });

                        });
                  </script>

   {%endblock%}